
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 3
 * @Author : WangRuoyu 
 * @Date : 2023/5/14 10:34
 */

#include <vector>
#include "iostream"
#include "algorithm"

using namespace std;

vector<string> getvec(string str) {
    vector<string> res;
    int tmp = -1;
    for (int i = 0; i < str.size(); ++i) {
        if (str[i] == '/') {
            string ss = str.substr(tmp + 1, i - tmp - 1);
            if (!ss.empty()) {
                res.push_back(ss);
            }
            tmp = i;
        }
    }
    string ss = str.substr(tmp + 1, str.size() - tmp - 1);
    if (!ss.empty()) {
        res.push_back(ss);
    }
    return res;
}

void walk(vector<string> cur, vector<string> path) {
    for (int i = 0; i < path.size(); ++i) {
        if (path[i] == ".") continue;
        else if (path[i] == "..") {
            if (cur.size()) cur.pop_back();
        } else {
            cur.push_back(path[i]);
        }
    }

    if (cur.empty()) cout << "/";
    else {
        for (int i = 0; i < cur.size(); ++i) {
            cout << "/" << cur[i];
        }
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    getchar();

    string str;
    getline(cin, str);
    vector<string> cur = getvec(str), ap;

    string strs[n];
    for (int i = 0; i < n; ++i) {
        getline(cin, strs[i]);
    }

    for (int i = 0; i < n; ++i) {
        str = strs[i];
        vector<string> path = getvec(str), ap;

        if (str.size() && str[0] == '/') walk(ap, path);
        else walk(cur, path);
    }

    return 0;
}